<template>
	<view class="flex-col page">
		<view class="flex-col self-stretch">

			<view class="flex-col list mt-9">
				<view class="flex-row justify-between items-center list-item mt-9" v-for="(item, index) in items"
					:key="index" @click="goEdit(item)">
					<view class="flex-row items-center flex-1">
						<image class="image_2"
							:src="item.asDefault?`/static/icons/location_default.png`:`/static/icons/location.png`" />
						<view class="flex-col items-start ml-17 flex-1">
							<text class="font">{{item.contact}}，{{item.phone}}</text>
							<text class="font_2 mt-9" style="line-height: 36rpx;">{{item.district}}{{item.address}}</text>
						</view>
					</view>
					<u-icon name="arrow-right"></u-icon>

				</view>
			</view>
		</view>
		<view class="flex-col justify-start items-center self-center text-wrapper mt-27" @click="goCreateEdit">
			<text class="font_2 text">添加新收货地址</text>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		props: {},
		data() {
			return {
				userInfo: {},
				source: 0,
				items: [],

			};
		},
		onPullDownRefresh() {

		},
		onReachBottom() {

		},
		onLoad(option) {
			if (option.source) {
				this.source = option.source
			}

		},
		onShow() {

			let token = this.$store.state.userToken;

			if (!token) {
				uni.navigateTo({
					url: '/pages-publics/login/login'
				})
			}

			this.userInfo = this.$store.state.userInfo;
			this.reSearch();
		},

		methods: {

			goEdit(item) {
				if (this.source == 1) {
			 
					uni.setStorageSync("select_address", item)
					uni.navigateBack();
				} else {
					uni.navigateTo({
						url: `/pages-users/addressEdit/addressEdit?id=${item.id}`
					})
				}

			},
			goCreateEdit() {
				uni.navigateTo({
					url: '/pages-users/addressEdit/addressEdit'
				})
			},
			reSearch() {
				this.items = [];
				this.$get({
					url: `${this.$Utils.ApiUrl}/recipients`,
					data: {

					}
				}).then(res => {
					this.items = res;
					console.log(res)
				})
			},
		},
	};
</script>

<style scoped lang="scss">
	.ml-17 {
		margin-left: 29.65rpx;
	}

	.mt-9 {
		margin-top: 15.7rpx;
	}

	.mt-27 {
		margin-top: 47.09rpx;
	}

	.page {
		padding-bottom: 948.84rpx;
		background-color: #f2f2f2;
		width: 100%;
		overflow-y: auto;
		overflow-x: hidden;
		height: 100%;

		.image {
			width: 100vw;
			height: 25.5814vw;
		}

		.list {
			padding: 0 17.44rpx;

			.list-item {
				padding: 48.84rpx 27.91rpx;
				background-color: #ffffff;
				border-radius: 17.44rpx;

				&:first-child {
					margin-top: 0;
				}

				.image_2 {
					width: 83.72rpx;
					height: 83.72rpx;
				}

				.font {
					font-size: 31.4rpx;
					font-family: SourceHanSansCN;
					line-height: 29.11rpx;
					color: #333333;
				}

				.image_3 {
					width: 62.79rpx;
					height: 62.79rpx;
				}
			}
		}

		.text-wrapper {
			padding: 20.93rpx 0;
			background-color: #ff0101;
			border-radius: 33.14rpx;
			width: 331.4rpx;

			.text {
				color: #ffffff;
				line-height: 22.6rpx;
			}
		}

		.font_2 {
			font-size: 24.42rpx;
			font-family: SourceHanSansCN;
			line-height: 22.9rpx;
			color: #666655;
		}
	}
</style>